/**
 * Copyright (c) 2018-2022, NXOS Development Team
 * SPDX-License-Identifier: Apache-2.0
 * 
 * Contains: nxos Kernel
 * 
 * Change Logs:
 * Date           Author            Notes
 * 2022-07-28     JasonHu           Init
 */

#include <nxos_mini.h>
#include <base/string.h>

/* import link script kernel symbols */
NX_IMPORT NX_Addr __NX_TextStart;
NX_IMPORT NX_Addr __NX_DataStart;
NX_IMPORT NX_Addr __NX_BssStart;
NX_IMPORT NX_Addr __NX_TextEnd;
NX_IMPORT NX_Addr __NX_DataEnd;
NX_IMPORT NX_Addr __NX_BssEnd;

NX_Addr NX_KernelGetSegmentStart(char * name)
{
    if (!NX_StrCmp(name, "text"))
    {
        return (NX_Addr )&__NX_TextStart + NX_KVADDR_OFFSET;
    }
    else if (!NX_StrCmp(name, "data"))
    {
        return (NX_Addr )&__NX_DataStart + NX_KVADDR_OFFSET;
    }
    else if (!NX_StrCmp(name, "bss"))
    {
        return (NX_Addr )&__NX_BssStart + NX_KVADDR_OFFSET;
    }
    else
    {
        return 0;
    }
}

NX_Addr NX_KernelGetSegmentEnd(char * name)
{
    if (!NX_StrCmp(name, "text"))
    {
        return (NX_Addr )&__NX_TextEnd + NX_KVADDR_OFFSET;
    }
    else if (!NX_StrCmp(name, "data"))
    {
        return (NX_Addr )&__NX_DataEnd + NX_KVADDR_OFFSET;
    }
    else if (!NX_StrCmp(name, "bss"))
    {
        return (NX_Addr )&__NX_BssEnd + NX_KVADDR_OFFSET;
    }
    else
    {
        return 0;
    }
}
